<template>
	<view class="container">
		<view v-if="this.popularList.length===0"  style="color: #CCCCCC;text-align: center;width: 100%;height: 500upx;line-height: 500upx;font-size: 32upx;"> 暂无数据</view>
		<view v-else v-for="(item, index) in popularList" :key="index"
				class="un-youxuan-section"
			>
			<view class="un-renimage-wrapper" @click="navToYouxuanAll(item)">
				<image :src="img+item.THUMB" mode="aspectFill"></image>
				<text class="iconfont icon-arrLeft-fill un-icon"></text>
			</view>
			
			<scroll-view class="floor-list" scroll-x>
				<view class="scoll-wrapper">
					<view 
						v-for="(item, index) in freshList" :key="index"
						class="floor-item"
						@click="navToDetailPage(item)"
					>
					
						<view >
							<view class="un-huangtuoyuan">
								新品
							</view>
							<image :src="img+item.THUMB" mode="aspectFill"></image>
						</view>
						
						
						<text class="un-title clamp">{{item.NAME}}</text>
						<text class="tit2 title2 clamp">{{item.SHORTINFO}}</text>
						<!-- <text class="price">￥{{item.SALEPRICE}}</text> -->
						<text class="price" v-if="!item.MULTIPAY">¥{{item.SALEPRICE}}</text>
						
						<text class="price" v-if="item.MULTIPAY==2&&item.OPPOINT!=0">积分:{{item.OPPOINT}}</text>
						<text class="price" v-if="item.MULTIPAY==2&&item.OPDEDU!=0">抵扣券:{{item.OPDEDU}}</text>
						<text class="price" v-if="item.MULTIPAY==2&&item.OPCOUPON!=0">惠券:{{item.OPCOUPON}}</text>
						
						<text class="price" v-if="item.MULTIPAY==3&&item.MUCHSELLERPRICE!=0">¥{{item.MUCHSELLERPRICE}}</text>
						<text class="price" v-if="item.MULTIPAY==3&&item.MUCHSELLERPRICE!=0&&item.MPPOINT!=0">+</text>
						<text class="price" v-if="item.MULTIPAY==3&&item.MPPOINT!=0">积分:{{item.MPPOINT}}</text>
						<text class="price" v-if="item.MULTIPAY==3&&(item.MUCHSELLERPRICE!=0||item.MPPOINT!=0)&&item.MPDEDU!=0">+</text>
						<text class="price" v-if="item.MULTIPAY==3&&item.MPDEDU!=0">抵扣券:{{item.MPDEDU}}</text>
						<text class="price" v-if="item.MULTIPAY==3&&(item.MUCHSELLERPRICE!=0||item.MPPOINT!=0||item.MPDEDU!=0)&&item.MPCOUPON!=0">+</text>
						<text class="price" v-if="item.MULTIPAY==3&&item.MPCOUPON!=0">惠券:{{item.MPCOUPON}}</text>
					</view>
					<view class="more">
						<text>查看全部</text>
						<text>More+</text>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {
		},
		data() {
			return {
				freshList:[],
				popularList:[],
				img:''
			}
		},
		onNavigationBarButtonTap() {  
		    console.log("点击了自定义按钮");  
		},
		onLoad() {
				this.img = getApp().globalData.imageAddress
				this.loadfresh();
				this.loadpopular();
			uni.startPullDownRefresh();
		},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {  
			//加载新鲜好物
			async loadfresh(){
					//加载信息
				this.$http.post("/goods/fresh",{
					SIGNATURE : uni.getStorageSync("SIGNATURE"),
					GP: '2'
				}).then((e)=>{
					e.data.OBJECT.map(item=>{
						if(item.ID){
							this.freshList.push(item)
						}
					})
				}).catch((err)=>{
					console.log("请求超时",err);
				})
				
			},
			//加载人气推荐
			async loadpopular(){
					//加载信息
				this.$http.post("/goods/fresh",{
					SIGNATURE : uni.getStorageSync("SIGNATURE"),
					GP: '3'
				}).then(e=>{
					e.data.OBJECT.map(item=>{
						if(item.ID){
							this.popularList.push(item)
						}
					})
				}).catch((err)=>{
					console.log("请求超时",err);
				})
				
			},
			//详情页
			navToDetailPage(item) {
				if(item.MULTIPAY){
					let ids=item.GOODID;
					let sid=item.ID;
					uni.navigateTo({
						url: `/pages/product/productExchange?id=${ids}&sid=${sid}`
					})
				}else{
					let id = item.ID;
					uni.navigateTo({
						url: `/pages/product/product?id=${id}`
					})
				}
			},
			//跳转优选列表
			navToYouxuanAll(item){
				let id=item.id;
				// uni.navigateTo({
				// 	url: '/pages/youxuan/youxuanall?id='+id,
				// 	success: res => {},
				// 	fail: () => {},
				// 	complete: () => {}
				// });
			}
			
		},
		
	}
</script>

<style lang="scss">
	page{
		background-color: #F5F5F5;
	}
	.un-youxuan-section{
		padding: 0upx 30upx 24upx;
		background: #fff;
		margin-bottom: 40upx;
		.un-renimage-wrapper{
			position: relative;
			image{
				width: 100%;
				height: 350upx;
			}
			.un-icon{
				position: absolute;
				z-index: 1;
				left: 100upx;
				top: 315upx;
				font-size: 50upx;
				color: #FFFFFF;
			}
		}
		.floor-list{
			margin-top: 20upx;
			margin-bottom: 40upx;
			white-space: nowrap;
		}
		.scoll-wrapper{
			display:flex;
			align-items: flex-start;
		}
		.floor-item{
			width: 250upx;
			margin-right: 20upx;
			font-size: $font-sm+2upx;
			color: $font-color-dark;
			line-height: 1.8;
			image{
				margin-top: 15upx;
				margin-left: 50upx;
				width: 160upx;
				height: 160upx;
				border-radius: 6upx;
			}
			.price{
				margin-left: 90upx;
				color: $uni-color-primary;
			}
			.tit2{
				
				font-size: $font-sm;
				color: $font-color-light;
			}
			.title2{
				margin-left: 20upx;
				font-size: 24upx;
				line-height: 40upx;
			}
			.un-title{
				margin-left: 20upx;
			}
			.un-huangtuoyuan{
				z-index: 1;
				position: absolute;
				margin-left: 180upx;
				margin-bottom: 200upx;
				top: 0upx;
				width: 79upx;
				height: 35upx;
				background: inherit;
				background-color: rgba(241, 151, 54, 1);
				box-sizing: border-box;
				border-width: 1upx;
				border-style: solid;
				border-color: rgba(241, 151, 54, 1);
				border-radius: 42upx;
				border-bottom-left-radius: 0upx;
				-moz-box-shadow: none;
				-webkit-box-shadow: none;
				box-shadow: none;
				font-family: '微软雅黑';
				font-weight: 404;
				font-style: normal;
				font-size: 22upx;
				color: #FFFFFF;
				text-align: center;
				line-height: 31upx
			}
		}
		.more{
			margin-top: 30upx;
			display:flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			flex-shrink: 0;
			width: 180upx;
			height: 180upx;
			border-radius: 6upx;
			background: #f3f3f3;
			font-size: $font-base;
			color: $font-color-light;
			text:first-child{
				margin-bottom: 4upx;
			}
		}
	}
</style>
